package com.qianbao.qianbaobusiness.ui.support.wechatprogram;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.baseandroid.config.Global;
import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author: Routee
 * @date 208/6/21
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class WechatSwitchShopActivity extends BaseMvpActivity<WechatSwitchShopView, WechatSwitchShopPresenter> implements WechatSwitchShopView {

    @BindView(R.id.tv_title)
    TextView     mTvTitle;
    @BindView(R.id.rv)
    RecyclerView mRv;
    private String mMerchantNo = "";
    private SingleSwitchShopRvAdapter mRvAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wechat_switch_shop;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        mTvTitle.setText("切换门店");
        Intent intent = getIntent();
        mMerchantNo = intent.getStringExtra("MerchantNo");
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {
        mRv.setLayoutManager(new LinearLayoutManager(this));
        if (mRvAdapter == null) {
            mRvAdapter = new SingleSwitchShopRvAdapter(this, mMerchantNo);
        }
        mRvAdapter.setOnClickListen(new SingleSwitchShopRvAdapter.ClickListen() {
            @Override
            public void click(String o) {
                Intent intent = new Intent();
                intent.putExtra("MerchantNo", o);
                setResult(RESULT_OK, intent);
                Global.setWechatAppSelectedMerchant(o);
                finish();
            }
        });
        mRv.setAdapter(mRvAdapter);
        List list = Global.getWechatAppInfos();
        mRvAdapter.resetData(list);
    }

    @OnClick(R.id.iv_back_toolbar)
    public void onViewClicked() {
        finish();
    }
}
